#include <bits/stdc++.h>

using namespace std;
int t,n[10010],m[10010],L[100010],V[1010];
int d[23][100010],v[23][100010],a[23][100010],p[100010];
int ans,bns,i,j,l,con,vt,pm;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(l=0;l<t;l++){
        cin>>n[l]>>m[l]>>L[l]>>V[l];
        con=con+n[l];
        pm=m[l];
        for(j=0;j<n[l];j++){
            cin>>d[l][j]>>v[l][j]>>a[l][j];
        }
        for(i=0;i<m[l];i++){
            cin>>p[i];
        }

        for(i=0;i<t;i++){
            for(j=0;j<n[l];j++){
                if(a[i][j]==0)ans++;
                if(a[i][j]<0)bns++;
            }
        }
        if(ans==con){
            vt=con;
            for(i=0;i<t;i++){
                for(j=0;j<n[l];j++){
                        if(v[i][j]>V[l])vt--;
                }
            }
            cout<<vt<<" "<<pm-1;
            return 0;
        }
        if(bns==con){
            cout<<"9"<<"7";
            return 0;
        }
    }
    return 0;
}

